/*import {Component, Inject, OnInit, Optional} from '@angular/core';
import {_HttpClient} from '@delon/theme';
import {MenuItem, TreeNode} from 'primeng/api';
import {UtilityService} from '../../../service/utils.service';
import {Router} from '@angular/router';
import {appConfig} from '../../../service/common';
import {GroupModule} from '../../../service/common.module';
import {NzModalService, NzNotificationService} from 'ng-zorro-antd';
import {ReuseTabService} from '@delon/abc';
import {CommondictServe} from '../../../service/commonDict';
import { ActivatedRoute, RouteReuseStrategy } from '@angular/router';
@Component({
  selector: 'app-group',
  templateUrl: './group.component.html',
})
export class GroupComponent implements OnInit {

    treedata: any[]; // tree组件数据
    treemenus: MenuItem[];
    searchTitle: string; // 树搜索框文字
    tabShow: boolean;
    id: string;
    modalVisible = false; // 弹出框默认关闭
    workItem: GroupModule = new GroupModule(); // 赋值
    // 枚举值
    groupType: any;
    groupStatus: any;
    isEdit = false; // 默认是新增
    groupData: any; // 树节点上的数据保存
    isRoot = false; // 是否是跟工作组
    loading = false;
    groupDetail: any; // 工作組的詳情
    guidOrg: any; // 查询所有机构
    selectionType: string; // 树结构类型
    groupName: string; // 树结构类型
    selectIndex = 0; // tab顺序 默认为0
    constructor(
        private http: _HttpClient,
        private router: Router,
        private utilityService: UtilityService,
        private modal: NzModalService,
        private nznot: NzNotificationService,
        private commondict: CommondictServe,
        private activatedRoute: ActivatedRoute, // 注入路由，接收到参数
        @Optional() @Inject(ReuseTabService) private reuseTabService: ReuseTabService,
    ) { }

    ngOnInit() {
        this.initData();
        // 枚举值转换
        this.groupType = appConfig.Enumeration.groupType;
        this.groupStatus = appConfig.Enumeration.groupStatus;
        this.searchTitle = '请输入工作组代码/名称';
        this.selectionType = 'single';

        this.reuseTabService.title = '工作组';
        this.tabShow = false;
        if(this.reuseTabService.items) {
            if(this.reuseTabService.items.length > 0) {
                for(let i = 0; i < this.reuseTabService.items.length; i ++) {
                    console.log(this.reuseTabService.items[i])
                    if(this.reuseTabService.items[i].title !== '工作组') { // 没有才添加
                        /!* 把当前路由添加到 tab 缓存中*!/
                        this.reuseTabService.store(this.activatedRoute.snapshot, '')
                    }
                }
            } else {
                /!* 把当前路由添加到 tab 缓存中*!/
                this.reuseTabService.store(this.activatedRoute.snapshot, '')
            }
        }
        // this.reuseTabService.store(this.activatedRoute.snapshot, '')
        this.dictQueryKey();
    }
    // 布局样式
    widthLeft = 7;
    widthRight = 17;
    isShow = true;
    text='收起'
    // 自定义卡片收缩方法
    toggleCollapsed(): void {
        this.isShow = !this.isShow;
        if(this.isShow === true){
            this.widthLeft = 7;
            this.widthRight = 17;
            this.text = '收起'
        }else{
            this.widthLeft = 2;
            this.widthRight = 22;
            this.text = '展开'
        }
    }

    // 根据key查询业务字典
    dictQueryKey() {
        this.commondict.queryDictKey(appConfig.dictKeyList.dictGroupType)
            .subscribe((val) => {
                this.groupType = val.result;
            })

        this.commondict.queryDictKey(appConfig.dictKeyList.dictGroupStatus)
            .subscribe((val) => {
                this.groupStatus = val.result;
            })
    }


    // tabs标题
    tabs = [
        {
            name   : '工作组详情',
            router : 'workGroup/group'
        },
        {
            name   : '员工',
            router : 'workGroup/groupEmp'
        },
        {
            name   : '岗位',
            router : 'workGroup/groupPost'
        },
        {
            name   : '应用权限',
            router : 'workGroup/authority'
        }
    ];


    initData() {
        this.treedata = [ // 默认根节点
            {
                'label': '工作组',
                'data': 'Documents Folder',
                'guid': 'null',
                'expandedIcon': 'fa fa-institution',
                'collapsedIcon': 'fa fa-institution',
                'children': [{}]
            }];

        // 从服务器获取树列表
            this.utilityService.getData(appConfig.serverUrl  + appConfig.API.omGroupsTree)
                .subscribe(
                    (val) => {
                        console.log(val.result)
                        for (let i = 0 ; i < val.result.length; i++) {
                            if (val.result[i].isleaf !== '是') { // 代表是最底层，没有下级了
                                val.result[i].collapsedIcon = 'anticon anticon-usb';
                            } else {
                                val.result[i].expandedIcon = 'fa fa-institution';
                                val.result[i].collapsedIcon = 'fa fa-institution';
                                val.result[i].children = val.result[i].childrens;
                                this.iteration(val.result[i].children);
                            }
                        }
                        this.treedata[0].children = val.result;
                        this.treedata.forEach( node => {
                            this.expandRecursive(node, true);
                        });
                    });

        this.treedata.forEach( node => {
            this.expandRecursive(node, true);
        });


        // 查询所有机构
        this.utilityService.getData(appConfig.serverUrl  + appConfig.API.orgQueryAll)
            .subscribe(
                (val) => {
                    this.guidOrg = val.result;
                });

    }


    iteration(node) {
        for (let i = 0; i < node.length; i++) {
            if (node[i].childrens !== undefined && node[i].childrens.length > 0) {
                node[i].expandedIcon = 'fa fa-institution';
                node[i].collapsedIcon = 'fa fa-institution';
                 node[i].children = node[i].childrens; // 重新赋值
                this.iteration(node[i].children); // 继续调用
            } else { // 字典项
                node[i].collapsedIcon = 'anticon anticon-usb';
                node[i].expandedIcon = 'anticon anticon-usb';
            }
        }
    }


    // 下拉刷新
    Unfold(event) {
        /!*this.getData(event.node);*!/
    }

    // 树的方法
    // 右击菜单传递值
    RightSelect(event) {
        if (event.node.guid === 'null') {
            this.treemenus = [
                {label: '新增根工作组', icon: 'fa fa-plus', command: (event) => this.addRootGroup()},
                // {label: '删除工作组', icon: 'fa fa-times', command: (event) => this.delectGroup()},
            ];
            this.groupData = event.node; // 绑定数据
        } else {
            this.treemenus = [
                {label: '新增子工作组', icon: 'fa fa-plus', command: (event) => this.addchildGroup()},
                {label: '修改工作组', icon: 'fa fa-edit', command: (event) => this.editGroup()},
                {label: '删除工作组', icon: 'fa fa-times', command: (event) => this.delectGroup()}];
            this.groupData = event.node; // 绑定数据
        }
    }
    // 左击树菜单节点信息
    TreeSelect(event) {
        console.log(event.node.code);
        this.id = event.node.code; // 先传guid 后期接口改成code 在传code
        if  (event.node.guid !== 'null') { // 只要不是跟机构就显示
            this.tabShow = true;
            this.selectIndex  = 0;
            this.groupName = event.node.label;
            this.router.navigate(['workGroup/group', this.id]); // 跳转路由
        } else {
            this.selectIndex  = 0
            this.router.navigate(['workGroup']);
            this.tabShow = false;
            this.groupName = event.node.label;
        }
    }

    // 拖拽方法
    dropEvent($event) {
        console.log($event)
        let originPonit = $event.dragNode.guid;
        let destinaPoint = $event.dropNode.guid;
        // 如果拖拽的目的地菜单是叶子菜单，拖拽目标目的地设为它的父菜单
        if ($event.dropNode.isleaf === 'Y') {
            destinaPoint = $event.dropNode.guidParents;
        }
        let  playOrder = $event.dragNode.displayOrder;
        let moveDate = {
            'targetGuid': destinaPoint,
            'moveGuid': originPonit,
            'order': 0
        };
        this.utilityService.postData(appConfig.serverUrl  + appConfig.API.queryMoveGroupLists , moveDate )
            .subscribe(
                (val) => {
                    this.initData()
                    this.nznot.create('success', '拖拽成功' , '拖拽成功');
                },
                (err) => {
                    // this.getData($event.dropNode); // 查询目标下的子集
                    this.initData()
                    this.nznot.create('error', err.msg , err.msg);
                }
            );
    }

    // 树节点搜索框的内容
    searchVal($event) {
        let jsonObj = {
            guid: 'null',
            name: $event
        }
        this.utilityService.postData(appConfig.serverUrl  + appConfig.API.grouptreeFilter, jsonObj)
            .subscribe(
                (val) => {
                    this.treedata =  [ // 默认根节点
                        {
                            'label': '工作组',
                            'data': 'Documents Folder',
                            'guid': 'null',
                            'expandedIcon': 'fa fa-institution',
                            'collapsedIcon': 'fa fa-institution',
                            'children': [{}]
                        }];
                    this.treedata[0].children = val.result.children;
                    for(let i = 0 ; i < val.result.children.length; i++) {
                        this.initData();
                    }
                    // 展开所有的
                    this.treedata.forEach( node => {
                        this.expandRecursive(node, true);
                    } );

                },
            );
    }

    // 树节点三个按钮方法
    clickFunc($event) {
        if($event === 'reset') {
            this.initData();
        } else if($event === 'expand') { // 全部展开方法
            this.treedata.forEach( node => {
                this.expandRecursive(node, true);
            });
        } else {
            this.tabShow = false;
        }
    }

    // 展开所有树节点的方法
    private expandRecursive(node:TreeNode, isExpand:boolean){
        node.expanded = isExpand;
        if(node.children){
            node.children.forEach( childNode => {
                this.expandRecursive(childNode, isExpand);
            } );
        }
    }


    // 新增跟工作组
    addRootGroup() {
        this.workItem = new GroupModule();
        this.modalVisible = true;
        this.isEdit = false;
        this.isRoot = true; // 调用新增工作组
        this.workItem.groupStatus = 'running'; // 弹出框默认选中
    }
    // 新增子工作组
    addchildGroup() {
        this.workItem = new GroupModule();
        this.modalVisible = true;
        this.isEdit = false;
        this.isRoot = false;
       this.workItem.groupStatus = 'running'; // 弹出框默认选中

    }

    // 枚举值转换
    statusgroup(event) {
        if (event.groupStatus === '正常') {
            event.groupStatus = 'running';
        } else if (event.groupStatus === '注销') {
            event.groupStatus = 'cancel';
        }
    }

    grouptype(event) {
        if (event.groupType === '普通工作组') {
            event.groupType = 'normal';
        } else if (event.groupType === '项目型') {
            event.groupType = 'project';
        } else if (event.groupType === '事务型') {
            event.groupType = 'affair';
        }
    }
    // 修改接口
    editGroup() {
        this.isEdit = true; // 是修改
        this.modalVisible = true;
        // 接口改变至之后 用code 而不是guid
        this.utilityService.getData(appConfig.serverUrl  + appConfig.API.omGroups + '/' + this.groupData.code)
            .subscribe(
                (val) => {
                    console.log(val)
                    this.grouptype(val.result);
                    this.statusgroup(val.result);
                    this.groupDetail = val.result; // 绑定工作组的详情
                    this.workItem = val.result; // 渲染数据
                },
            );
    }


    save() {
        const jsonOption = this.workItem;
        // jsonOption.groupOrg = 'ORG北京总行00007'; // 写死机构
        // jsonOption.guidName = this.workItem.groupName; // 写死机构
        if (!this.isEdit) {
            if (this.isRoot) { // 调用新增跟工作组接口
                this.utilityService.postData(appConfig.serverUrl  + appConfig.API.groupRoot, jsonOption)
                    .subscribe(
                        (val) => {
                            this.initData()
                            this.nznot.create('success', val.msg , val.msg);
                        },
                        (error) => {
                            this.nznot.create('error', error.msg , error.msg);
                        }
                    );
            } else {
                jsonOption.guidParents = this.groupData.guid;
                this.utilityService.postData(appConfig.serverUrl  + appConfig.API.groupChild, jsonOption)
                    .subscribe(
                        (val) => {
                            this.initData()
                            this.nznot.create('success', val.msg , val.msg);
                        },
                        (error) => {
                            this.nznot.create('error', error.msg , error.msg);
                        }
                    );
            }
        } else {
            this.utilityService.putData(appConfig.serverUrl  + appConfig.API.omGroups, jsonOption)
                .subscribe(
                    (val) => {
                        this.nznot.create('success', val.msg , val.msg);
                        this.initData()

                    },
                    (error) => {
                        this.nznot.create('error', error.msg , error.msg);
                    }
                );
        }
        this.modalVisible = false;
    }

    delectGroup() {
        console.log(this.groupData)
        this.modal.open({
            title: '是否删除',
            content: '您确认要删除该工作组吗? 删除该工作组下所有子工作组都会被一并删除',
            okText: '确定',
            cancelText: '取消',
            onOk: () => {
                this.utilityService.deleatData(appConfig.serverUrl  + appConfig.API.omGroups + '/' + this.groupData.code)
                    .subscribe(
                        (val) => {
                            this.initData()
                            this.tabShow = false;
                            this.nznot.create('success', val.msg , val.msg);
                        },
                        (error) => {
                            this.nznot.create('error', error.msg , error.msg);
                        }
                    );
            },
            onCancel: () => {
                console.log('失败');
            }
        });
    }

    // 360跳转
    getRouter(it) {
        this.selectIndex = it.index;
        this.router.navigate([this.tabs[it.index].router, this.id]);
    }

}*/



/*代码重构*/
import {Component, Inject, OnInit, Optional} from '@angular/core';
import {_HttpClient} from '@delon/theme';
import {MenuItem, TreeNode} from 'primeng/api';
import {UtilityService} from '../../../service/utils.service';
import {Router} from '@angular/router';
import {appConfig} from '../../../service/common';
import {GroupModule, PageModule} from '../../../service/common.module';
import {NzModalService, NzNotificationService} from 'ng-zorro-antd';
import {ReuseTabService} from '@delon/abc';
import {CommondictServe} from '../../../service/commonDict';
import { ActivatedRoute, RouteReuseStrategy } from '@angular/router';
import * as moment from 'moment';
import {EmpModule} from '../../../service/emp';
import {PostModule} from '../../../service/post';
import {DA_SERVICE_TOKEN, ITokenService} from '@delon/auth';
@Component({
    selector: 'app-group',
    templateUrl: './group.component.html',
})
export class GroupComponent implements OnInit {

    treedata: any[]; // tree组件数据
    treemenus: MenuItem[];
    searchTitle: string; // 树搜索框文字
    tabShow: boolean;
    id: string;
    GroupVisible = false; // 弹出框默认关闭
    workItem: GroupModule = new GroupModule(); // 赋值
    // 枚举值
    groupType: any;
    groupStatus: any;
    isGroupEdit = false; // 默认是新增
    groupData: any; // 树节点上的数据保存
    isRoot = false; // 是否是跟工作组
    loading = false;
    groupDetail: any; // 工作組的詳情
    guidOrg: any; // 查询所有机构
    selectionType: string; // 树结构类型
    groupName: string; // 树结构类型
    selectIndex = 0; // tab顺序 默认为0
    funcBhvList: any; // 后台返回的行为列表
    appcofList: any;
    constructor(
        private http: _HttpClient,
        private router: Router,
        private utilityService: UtilityService,
        private modal: NzModalService,
        private nznot: NzNotificationService,
        private commondict: CommondictServe,
        private activatedRoute: ActivatedRoute, // 注入路由，接收到参数
        @Optional() @Inject(ReuseTabService) private reuseTabService: ReuseTabService,
    ) { }

    ngOnInit() {
        this.appcofList  = appConfig;
        this.initData();
        // 枚举值转换
        this.searchTitle = '请输入工作组代码/名称';
        this.selectionType = 'single';
        this.reuseTabService.title = '工作组';
        this.tabShow = false;
        if(this.reuseTabService.items) {
            if(this.reuseTabService.items.length > 0) {
                for(let i = 0; i < this.reuseTabService.items.length; i ++) {
                    console.log(this.reuseTabService.items[i])
                    if(this.reuseTabService.items[i].title !== '工作组') { // 没有才添加
                        /* 把当前路由添加到 tab 缓存中*/
                        this.reuseTabService.store(this.activatedRoute.snapshot, '')
                    }
                }
            } else {
                /* 把当前路由添加到 tab 缓存中*/
                this.reuseTabService.store(this.activatedRoute.snapshot, '')
            }
        }
        this.dictQueryKey();
    }
    // 布局样式
    widthLeft = 7;
    widthRight = 17;
    isShow = true;
    text='收起'
    // 自定义卡片收缩方法
    toggleCollapsed(): void {
        this.isShow = !this.isShow;
        if(this.isShow === true){
            this.widthLeft = 7;
            this.widthRight = 17;
            this.text = '收起'
        }else{
            this.widthLeft = 2;
            this.widthRight = 22;
            this.text = '展开'
        }
    }

    // 根据key查询业务字典
    dictQueryKey() {
        this.commondict.queryDictKey(appConfig.dictKeyList.dictGroupType)
            .subscribe((val) => {
                this.groupType = val.result;
            })

        this.commondict.queryDictKey(appConfig.dictKeyList.dictGroupStatus)
            .subscribe((val) => {
                this.groupStatus = val.result;
            })

        this.commondict.queryDictKey(appConfig.dictKeyList.gender)
            .subscribe((val) => {
                this.gender = val.result;
            })

        this.commondict.queryDictKey(appConfig.dictKeyList.empStatus)
            .subscribe((val) => {
                this.empType = val.result;
            })

        this.commondict.queryDictKey(appConfig.dictKeyList.postStatus)
            .subscribe((val) => {
                this.postStatus = val.result;
            })

        this.commondict.queryDictKey(appConfig.dictKeyList.positionType)
            .subscribe((val) => {
                this.positionType = val.result;
            })
    }


    // tabs标题
    tabs = [
        {
            name   : '工作组详情',
            router : 'workGroup/group',
            id: 'info'
        },
        {
            name   : '员工',
            router : 'workGroup/groupEmp',
            id: 'emp'
        },
        {
            name   : '岗位',
            router : 'workGroup/groupPost',
            id:'post'
        },
        {
            name   : '应用权限',
            router : 'workGroup/authority',
            id: 'authority'
        }
    ];


    initData() {
        this.treedata = [ // 默认根节点
            {
                'label': '工作组',
                'data': 'Documents Folder',
                'guid': 'null',
                'expandedIcon': 'fa fa-institution',
                'collapsedIcon': 'fa fa-institution',
                'children': [{}]
            }];

        // 从服务器获取树列表
        this.utilityService.getData(appConfig.serverUrl  + appConfig.API.omGroupsTree)
            .subscribe(
                (val) => {
                    for (let i = 0 ; i < val.result.length; i++) {
                        if (val.result[i].isleaf !== '是') { // 代表是最底层，没有下级了
                            val.result[i].collapsedIcon = 'anticon anticon-usb';
                        } else {
                            val.result[i].expandedIcon = 'fa fa-institution';
                            val.result[i].collapsedIcon = 'fa fa-institution';
                            val.result[i].children = val.result[i].childrens;
                            this.iteration(val.result[i].children);
                        }

                    }
                    this.treedata[0].children = val.result;
                    this.treedata.forEach( node => {
                        this.expandRecursive(node, true);
                    });
                });

        this.treedata.forEach( node => {
            this.expandRecursive(node, true);
        });


        // 查询所有机构
        this.utilityService.getData(appConfig.serverUrl  + appConfig.API.orgQueryAll)
            .subscribe(
                (val) => {
                    this.guidOrg = val.result;
                });

    }


    iteration(node) {
        for (let i = 0; i < node.length; i++) {
            if (node[i].childrens !== undefined && node[i].childrens.length > 0) {
                node[i].expandedIcon = 'fa fa-institution';
                node[i].collapsedIcon = 'fa fa-institution';
                node[i].children = node[i].childrens; // 重新赋值
                this.iteration(node[i].children); // 继续调用
            } else { // 字典项
                node[i].collapsedIcon = 'anticon anticon-usb';
                node[i].expandedIcon = 'anticon anticon-usb';
            }
        }
    }


    // 下拉刷新
    Unfold(event) {
        /*this.getData(event.node);*/
    }

    // 树的方法
    // 右击菜单传递值
    RightSelect(event) {
        if (event.node.guid === 'null') {
            this.treemenus = [
                {label: '新增根工作组', icon: 'fa fa-plus', id: appConfig.funcObject.group.addRootGroup,  command: (event) => this.addRootGroup()},
                // {label: '删除工作组', icon: 'fa fa-times', command: (event) => this.delectGroup()},
            ];
            this.groupData = event.node; // 绑定数据
        } else {
            this.treemenus = [
                {label: '新增子工作组', icon: 'fa fa-plus',id: appConfig.funcObject.group.addchildGroup, command: (event) => this.addchildGroup()},
                {label: '修改工作组', icon: 'fa fa-edit', id: appConfig.funcObject.group.eidtGroup,command: (event) => this.editGroup()},
                {label: '删除工作组', icon: 'fa fa-times',id: appConfig.funcObject.group.delGroup, command: (event) => this.delectGroup()}];
            this.groupData = event.node; // 绑定数据
        }
    }
    // 左击树菜单节点信息
    TreeSelect(event) {
        console.log(event)
        this.id = event.node.code; // 先传guid 后期接口改成code 在传code
        if  (event.node.guid !== 'null') { // 只要不是跟机构就显示
            this.tabShow = true;
            this.selectIndex  = 0;
            this.groupName = event.node.label;
            this.tabId = 'info'
            /* 初始化详情信息 */
            this.guidGroup = this.id; // 绑定工作组guid
            this.isInfoEdit = true;
            this.dictQueryKey();
            this.getInit();
            // 查询所有机构
            this.utilityService.getData(appConfig.serverUrl  + appConfig.API.orgQueryAll)
                .subscribe(
                    (val) => {
                        this.guidOrg = val.result;
                    });
        } else {
            this.selectIndex  = 0
            this.router.navigate(['workGroup']);
            this.tabShow = false;
            this.groupName = event.node.label;
        }
    }

    // 拖拽方法
    dropEvent($event) {
        console.log($event)
        let originPonit = $event.dragNode.guid;
        let destinaPoint = $event.dropNode.guid;
        // 如果拖拽的目的地菜单是叶子菜单，拖拽目标目的地设为它的父菜单
        if ($event.dropNode.isleaf === 'Y') {
            destinaPoint = $event.dropNode.guidParents;
        }
        let  playOrder = $event.dragNode.displayOrder;
        let moveDate = {
            'targetGuid': destinaPoint,
            'moveGuid': originPonit,
            'order': 0
        };
        this.utilityService.postData(appConfig.serverUrl  + appConfig.API.queryMoveGroupLists , moveDate )
            .subscribe(
                (val) => {
                    this.initData()
                    this.nznot.create('success', '拖拽成功' , '拖拽成功');
                },
                (err) => {
                    // this.getData($event.dropNode); // 查询目标下的子集
                    this.initData()
                    this.nznot.create('error', err.msg , err.msg);
                }
            );
    }

    // 树节点搜索框的内容
    searchVal($event) {
        let jsonObj = {
            guid: 'null',
            name: $event
        }
        this.utilityService.postData(appConfig.serverUrl  + appConfig.API.grouptreeFilter, jsonObj)
            .subscribe(
                (val) => {
                    this.treedata =  [ // 默认根节点
                        {
                            'label': '工作组',
                            'data': 'Documents Folder',
                            'guid': 'null',
                            'expandedIcon': 'fa fa-institution',
                            'collapsedIcon': 'fa fa-institution',
                            'children': [{}]
                        }];
                    this.treedata[0].children = val.result.children;
                    for(let i = 0 ; i < val.result.children.length; i++) {
                        this.initData();
                    }
                    // 展开所有的
                    this.treedata.forEach( node => {
                        this.expandRecursive(node, true);
                    } );

                },
            );
    }

    // 树节点三个按钮方法
    clickFunc($event) {
        if($event === 'reset') {
            this.initData();
        } else if($event === 'expand') { // 全部展开方法
            this.treedata.forEach( node => {
                this.expandRecursive(node, true);
            });
        } else {
            this.tabShow = false;
        }
    }

    // 展开所有树节点的方法
    private expandRecursive(node:TreeNode, isExpand:boolean){
        node.expanded = isExpand;
        if(node.children){
            node.children.forEach( childNode => {
                this.expandRecursive(childNode, isExpand);
            } );
        }
    }


    // 新增跟工作组
    addRootGroup() {
        this.workItem = new GroupModule();
        this.GroupVisible = true;
        this.isGroupEdit = false;
        this.isRoot = true; // 调用新增工作组
        this.workItem.groupStatus = 'running'; // 弹出框默认选中
    }
    // 新增子工作组
    addchildGroup() {
        this.workItem = new GroupModule();
        this.GroupVisible = true;
        this.isGroupEdit = false;
        this.isRoot = false;
        this.workItem.groupStatus = 'running'; // 弹出框默认选中

    }

    // 枚举值转换
    statusgroup(event) {
        if (event.groupStatus === '正常') {
            event.groupStatus = 'running';
        } else if (event.groupStatus === '注销') {
            event.groupStatus = 'cancel';
        }
    }

    grouptype(event) {
        if (event.groupType === '普通工作组') {
            event.groupType = 'normal';
        } else if (event.groupType === '项目型') {
            event.groupType = 'project';
        } else if (event.groupType === '事务型') {
            event.groupType = 'affair';
        }
    }
    // 修改接口
    editGroup() {
        this.GroupVisible = true;
        this.isGroupEdit = true; // 是修改
        // 接口改变至之后 用code 而不是guid
        this.utilityService.getData(appConfig.serverUrl  + appConfig.API.omGroups + '/' + this.groupData.code)
            .subscribe(
                (val) => {
                    this.grouptype(val.result);
                    this.statusgroup(val.result);
                    this.groupDetail = val.result; // 绑定工作组的详情
                    this.workItem = val.result; // 渲染数据
                },
            );
    }


    Groupsave() {
        const jsonOption = this.workItem;
        // jsonOption.groupOrg = 'ORG北京总行00007'; // 写死机构
        // jsonOption.guidName = this.workItem.groupName; // 写死机构
        if (!this.isGroupEdit) {
            if (this.isRoot) { // 调用新增跟工作组接口
                this.utilityService.postData(appConfig.serverUrl  + appConfig.API.groupRoot, jsonOption)
                    .subscribe(
                        (val) => {
                            this.initData()
                            this.nznot.create('success', val.msg , val.msg);
                        },
                        (error) => {
                            this.nznot.create('error', error.msg , error.msg);
                        }
                    );
            } else {
                jsonOption.guidParents = this.groupData.guid;
                this.utilityService.postData(appConfig.serverUrl  + appConfig.API.groupChild, jsonOption)
                    .subscribe(
                        (val) => {
                            this.initData()
                            this.nznot.create('success', val.msg , val.msg);
                        },
                        (error) => {
                            this.nznot.create('error', error.msg , error.msg);
                        }
                    );
            }
        } else {
            this.utilityService.putData(appConfig.serverUrl  + appConfig.API.omGroups, jsonOption)
                .subscribe(
                    (val) => {
                        this.nznot.create('success', val.msg , val.msg);
                        this.initData()

                    },
                    (error) => {
                        this.nznot.create('error', error.msg , error.msg);
                    }
                );
        }
        this.GroupVisible = false;
    }

    delectGroup() {
        console.log(this.groupData)
        this.modal.open({
            title: '是否删除',
            content: '您确认要删除该工作组吗? 删除该工作组下所有子工作组都会被一并删除',
            okText: '确定',
            cancelText: '取消',
            onOk: () => {
                this.utilityService.deleatData(appConfig.serverUrl  + appConfig.API.omGroups + '/' + this.groupData.code)
                    .subscribe(
                        (val) => {
                            this.initData()
                            this.tabShow = false;
                            this.nznot.create('success', val.msg , val.msg);
                        },
                        (error) => {
                            this.nznot.create('error', error.msg , error.msg);
                        }
                    );
            },
            onCancel: () => {
                console.log('失败');
            }
        });
    }

    tabId: string;
    // 360跳转
    getRouter(it) {
        this.selectIndex = it.index;
        if(it.index === 0) {
            this.tabId = 'info'
            this.initInfo();
        } else if(it.index === 1) {
            this.tabId = 'emp'
            this.initEmp()
        } else if(it.index === 2) {
            this.tabId = 'post'
            this.InitPost();
        } else {
            this.tabId = 'authority';
            this.getInitAuthority();
        }
    }


    /*-----------------------------------工作组详情---------------------------------*/
    guidGroup: string;
    isInfoEdit: boolean;
    // 枚举值转换
    typeGroup(event) {
        if (event.groupType === '普通工作组') {
            event.groupType = 'normal';
        } else if (event.groupType === '项目型') {
            event.groupType = 'project';
        }   else if (event.groupType === '事务型') {
            event.groupType = 'affair';
        }
    }


    typeStatus(event) {
        if (event.groupStatus === '正常') {
            event.groupStatus = 'running';
        } else if (event.groupStatus === '注销') {
            event.groupStatus = 'cancel';
        }
    }


    initInfo() {
        /* 初始化详情信息 */
        this.guidGroup = this.id; // 绑定工作组guid
        this.isInfoEdit = true;
        this.dictQueryKey();
        this.getInit();
        // 查询所有机构
        this.utilityService.getData(appConfig.serverUrl  + appConfig.API.orgQueryAll)
            .subscribe(
                (val) => {
                    this.guidOrg = val.result;
                });
    }
    getInit() {
        this.utilityService.getData(appConfig.serverUrl  + appConfig.API.omGroups + '/' + this.guidGroup)
            .subscribe(
                (val) => {
                    console.log(val.result)
                    if (val.result.groupStatus === '正常') {
                        this.groupData = true;
                    } else {
                        this.groupData = false;
                    }
                    // 枚举值转换
                    this.typeGroup(val.result)
                    this.typeStatus(val.result)
                    this.workItem = val.result; // 渲染数据
                    console.log(this.workItem)
                },
            );
    }


    groupEdit() {
        this.isInfoEdit = false;
    }

    groupSave() {
        const jsonOption =  this.workItem;
        this.utilityService.putData(appConfig.serverUrl  + appConfig.API.omGroups, jsonOption)
            .subscribe(
                (val) => {
                    this.nznot.create('success', val.msg , val.msg);
                },(error) => {
                    this.nznot.create('error', error.msg , error.msg);
                }

            );
        this.isInfoEdit = true;
    }


    // 启动岗位
    openGroup() {

        this.modal.open({
            title: '是否启用下级工作组',
            content: '确定则该工作组下所有工作组都会被启用，取消则只启用当前工作组',
            okText: '确定',
            cancelText: '取消',
            onOk: () => {
                this.utilityService.putData(appConfig.serverUrl  + appConfig.API.omGroups + '/' + this.guidGroup  + '/reenable' + '/' + true)
                    .subscribe(
                        (val) => {
                            this.nznot.create('success', val.msg , val.msg);
                            this.getInit();
                        },
                        (error) => {
                            this.nznot.create('error', error.msg , error.msg);
                        });
            },
            onCancel: () => {
                this.utilityService.putData(appConfig.serverUrl  + appConfig.API.omGroups + '/' + this.guidGroup  + '/reenable' + '/' + false)
                    .subscribe(
                        (val) => {
                            this.nznot.create('success', val.msg , val.msg);
                            this.getInit();
                        },
                        (error) => {
                            this.nznot.create('error', error.msg , error.msg);
                        });
            }
        });

    }
    // 注销岗位
    cancelGroup() {
        this.utilityService.putData(appConfig.serverUrl  + appConfig.API.omGroups + '/' + this.guidGroup  + '/enable')
            .subscribe(
                (val) => {
                    console.log(val)
                    this.nznot.create('success', val.msg , val.msg);
                    this.getInit();
                },
                (error) => {
                    this.nznot.create('error', error.msg , error.msg);
                });
    }



/*--------------------------------------------工作组下员工--------------------------------------------------*/
    gender: any;
    // 员工状态
    empType: any;
    emppages: PageModule = new PageModule();
    emp: EmpModule = new EmpModule();
    emppost: any;
    selectedEmpRow: any; // 总数
    // 证件类型
    paperType: any;
    expandForm = false;
    selectedOption;
    searchOptions;
    EmppageIndex = 1; // 当前页数
    type = [
        { text: '正常', value: false, key: 'normal' },
        { text: '挂起', value: false, key: 'hang' },
        { text: '注销', value: false, key: 'logOut' },
        { text: '锁定', value: false, key: 'locking' }
    ];
    // 操作员类型
    radioValue = [
        { text: '新建默认操作员', value: false, key: 'creat' },
        { text: '选择已存在的', value: false, key: 'extant' },
        { text: '暂不选择操作员', value: false, key: 'noselect' }
    ];

    // 弹出框默认关闭
    EmpmodalVisible = false;
    Emptotal: number;
    Empdata: any[] = []; // 表格数据
    EmpoheaderData = [  // 配置表头内容
        {value: '员工姓名' , key: 'empName', isclick: false},
        {value: '操作员', key: 'userId',  isclick:  false},
        {value: '基本岗位' , key: 'positionName', isclick: false},
        {value: '员工状态' , key: 'empstatus', isclick: false},
        {value: '电话号码' , key: 'mobileno', isclick: false},
        {value: '入职日期' , key: 'indate', isclick: false},
    ];
    orgGuid: '';
    EmpconfigTitle: any;
    EmpmoreData = {
        morebutton: true,
        buttons: [
            {key: 'Overview' , value: '查看概况'}
        ]
    };
    empAddType: any;
    codeGroup: string; // 工作组code
    // 选择状态
    itemType = [
        {value: '当前机构员工', key: 'orgEmp'},
        {value: '其他机构员工', key: 'orginfoEmp'},
    ];
    // 表头按钮
    Empbuttons = [
        {key: 'add', value: '新增员工', buttonCode: appConfig.funcObject.group.addGroupEmp}
    ]
    groupGuid: string;

    /*初始化员工*/
    initEmp() {
        this.codeGroup = this.id; // 拿到父组件传过来的组织机构的guid来进行操作
        // 枚举值转换
        this.gender = appConfig.Enumeration.gender;
        this.paperType = appConfig.Enumeration.paperType;
        this.empType = appConfig.Enumeration.empType;
        this.EmpconfigTitle = {value: '', buttonCode: appConfig.funcObject.group.queryGroup}; // 不需要，直接给查询权限，百分之百有
        this.queryGroupEmp(); // 查询工作组下的员工
        this.dictQueryKey();
        this.queryEmpOrgPost();
        this.queryGroupInfo();
    }
    queryGroupInfo() {
        this.utilityService.getData(appConfig.serverUrl  + appConfig.API.omGroups + '/' + this.codeGroup)
            .subscribe(
                (val) => {
                    console.log(val.result)
                    this.orgGuid = val.result.guidOrg; // 绑定机构guid
                    this.groupGuid = val.result.guid;
                    this.reuseTabService.title = val.result.groupName + '下员工'
                },
            );
    }


    queryEmpOrgPost() {
        // 查询所有岗位
        this.utilityService.getData(appConfig.serverUrl + appConfig.API.listsByOrgId + '/' + this.groupGuid)
            .subscribe(
                (val) => {
                    this.emppost = val.result;
                });
    }

    queryGroupEmp(option?) {

        if (option) {
            this.EmppageIndex = 1;
        }

        const page = {
            condition: this.objJson, // 搜索内容
            page: {
                current: this.EmppageIndex,
                size: this.emppages.size,
            }
        };
        this.utilityService.postData(appConfig.serverUrl + appConfig.API.omGroups + '/' + this.codeGroup + '/emp', page)
            .subscribe(
                (val) => {
                    console.log(val.result)
                    for (let i = 0; i < val.result.records.length; i++) {
                        val.result.records[i].buttonData = [{key: 'dels', value: '删除', buttonCode: appConfig.funcObject.group.delGroupEmp}];
                        if(val.result.records[i].indate) {
                            val.result.records[i].indate =  moment(val.result.records[i].indate).format('YYYY-MM-DD');
                        }
                    }

                    this.Empdata = val.result.records;
                    this.Emptotal = val.result.total;
                });
    }

    // 查询机构下员工,感觉应该是查出不在当前工作组下的
    getEmpData(orgGuid) {
        this.utilityService.getData(appConfig.serverUrl + appConfig.API.omGroups + '/' + this.codeGroup + '/empNotIn/' + orgGuid, {})
            .subscribe(
                (val) => {
                    this.searchOptions = val.result;
                });
    }

    // 查询机构之外的其他员工,同样应该是不在当前工作组下的
    getallData(e) {

    }


    // 列表组件传过来的内容
    addEmpHandler(event) {
        this.empAddType = 'orgEmp'; // 默认是当前机构员工
        this.getEmpData(this.orgGuid);
        this.selectedOption = null; // 默认清空
        this.EmpmodalVisible = true;
    }


    // 列表传入的翻页数据
    monitorEmpHandler(event) {
        this.EmppageIndex = event;
        this.queryGroupEmp();

    }

    // 接受子组件删除的数据 单条还是多条
    deleatEmpData(event) {

    }


    // 列表按钮方法
    buttonEmpDataHandler(event) {

    }


    // 右侧按钮方法
    buttonEmpEvent(e) {
        console.log(e)
        if (e.names) {
            if (e.names.key === 'dels') {
                this.modal.open({
                    title: '是否删除',
                    content: '您是否确认删除所选员工?',
                    okText: '确定',
                    cancelText: '取消',
                    onOk: () => {
                        this.utilityService.deleatData(appConfig.serverUrl + appConfig.API.omGroups + '/' + this.codeGroup + '/empGroup/' + e.guid)
                            .subscribe(
                                (val) => {
                                    this.nznot.create('success', val.msg , val.msg);
                                    if ( !(( this.Emptotal - 1) % 10)) {
                                        // if ( !(( this.Emptotal - this.acfundata.length) % 10)) { // 支持批量删除的方法
                                        this.emppages.pi -- ;
                                        this.queryGroupEmp();
                                    }
                                    this.queryGroupEmp();
                                },
                                (error) => {
                                    this.nznot.create('error', error.msg , error.msg);
                                });
                    },
                    onCancel: () => {
                        console.log('取消成功');
                    }
                });
            }
        }
    }


    EmpdeleteBatch(event) {
        this.modal.open({
            title: '是否删除',
            content: '您是否确认删除这' + event.length + '条员工吗?',
            okText: '确定',
            cancelText: '取消',
            onOk: () => {
                let delarray = [];
                for( let i = 0; i < event.length; i++) {
                    delarray.push(event[i].guid);
                }
                let deletaObj = {
                    deleteList: delarray,
                    guid: this.groupGuid
                }
                this.utilityService.postData(appConfig.serverUrl + appConfig.API.empGroypDel, deletaObj )
                    .subscribe(
                        (val) => {
                            this.queryGroupEmp();
                            this.selectedEmpRow = [];
                            this.nznot.create('success', val.msg , val.msg);
                        },
                        (error) => {
                            this.nznot.create('error', error.msg , error.msg);
                        });
            },
            onCancel: () => {
                this.queryGroupEmp();
                this.selectedEmpRow = [];
            }
        });
    }



    objJson = {};
    // 搜索框
    Empsearch() {
        this.objJson = this.emp;
        this.queryGroupEmp(this.emp);
    }



    Empreset() {
        this.emp = new EmpModule();
        this.objJson = {};
        this.queryGroupEmp();
    }


    // 弹出框保存组件
    Empsave() {
        this.EmpmodalVisible = false;
    }

    // 点击入职的方法
    select(i) {

    }

    // 查看选择内容
    checkSelect(e) {
        if (e === 'orgEmp') { // 查询机构下员工
            this.getEmpData(this.orgGuid);
        } else { // 查询所有员工
            this.getallData(this.orgGuid);
        }
    }

    appEmpClick() {
        const jsonObj = {
            groupCode: this.codeGroup,
            guidEmp: this.selectedOption,
        }
        this.utilityService.postData(appConfig.serverUrl + appConfig.API.empGroup, jsonObj)
            .subscribe(
                (val) => {
                    this.nznot.create('success', val.msg , val.msg);
                    this.EmpmodalVisible = false;
                    this.queryGroupEmp();
                },
                (error) => {
                    this.nznot.create('error', error.msg , error.msg);
                });

    }

    // 邀请员工, 先放着，还没有通知功能
    invite() {

    }






    /*----------------------------------------------工作组下岗位-----------------------------*/
    post: PostModule = new PostModule();
    postAdd: PostModule = new PostModule();

    ifshow: boolean = true;

    // 岗位类型
    positionType: any;
    // 状态
    postStatus: any;
    page: any;
    postAddEdit: string; // 新增/修改 崗位
    appConfit: string; // 是否有修改按钮
    postTitle: string;
    // blDuct 所属职务
    blDuct= [
        {key: 'practice' , value: '行长'},
        {key: 'primary' , value: '业务经理'},
        {key: 'intermediate' , value: '理财经理'},
        {key: 'Senior' , value: '营销经理'},
        {key: 'scientist' , value: '大厅经理'},
        {key: 'management' , value: '会计'},
        {key: 'Director' , value: '总管'},
    ];

    posttotal: number;
    postGuid: string;


    // 岗位员工
    GroupmodalVisible = false;
    empdistribution = false;
    modelSelect: boolean; // 弹出框内容选择

    isEdit = false; // 默认是新增 不是修改
    postdata: any[] = []; // 表格数据
    isappcodeSlash = false; // 验证服务
    headerPostData = [  // 配置表头内容
        {value: '岗位名称' , key: 'positionName', isclick: false},
        {value: '上级岗位' , key: 'parentName', isclick: false},
        {value: '岗位状态' , key: 'positionStatus', isclick: false},
        {value: '在岗员工数' , key: 'empNum', isclick: true},
        {value: '岗位有效日期' , key: 'startDate', isclick: false},
        {value: '岗位失效日期' , key: 'endDate', isclick: false},
    ];


    morePostData = {
        morebutton: true,
        buttons: [
            {key: 'Overview' , value: '查看概况'},
        ]
    };
    // switch控制
    parentPost = false;
    startDate = false;
    endDate = false;
    selectedPostRows: any; // 选择的总数

    // 表头按钮
    buttonsPost = [
        {key: 'add', value: '新增岗位', buttonCode: appConfig.funcObject.group.delGrouppost}
    ]

    copy: any;
    pageIndex = 1; // 当前页数
    groupCode: string;
    Parentsguid: any;
    configPostTitle: any;
    InitPost() {
        this.groupCode  = this.id; // 拿到父组件传过来的组织机构的guid来进行操作
        this.getPostData(); // 只会触发一次，但是ngchanges并不会触发咋办
        this.queryGroup(this.groupCode);
        this.dictQueryKey();
        // 查询工作组详情
        this.utilityService.getData(appConfig.serverUrl  + appConfig.API.omGroups + '/' + this.groupCode)
            .subscribe(
                (val) => {
                    this.reuseTabService.title = val.result.groupName + '下岗位'
                },
            );
        this.configPostTitle = {value: '修改', buttonCode: appConfig.funcObject.group.delGrouppost} // 无修改工作组岗位，先写新增工作组岗位接口，明天改
    }


    getPostData(option?) { // 初始化请求后台数据
        if (option) {
            this.pageIndex = 1;
        }
        this.page = {
            condition: this.objJSon, // 搜索内容
            page: {
                current: this.pageIndex,
                size: this.post.size,
            }
        };

        // 查询工作组下所有岗位
        this.utilityService.postData(appConfig.serverUrl + appConfig.API.omGroups + '/' + this.groupCode + '/positionIn',  this.page)
            .subscribe(
                (val) => {
                    // 没有在岗员工，模拟一下
                    for ( let i = 0; i < val.result.records.length; i++) {
                        if ( val.result.records[i].positionStatus === '正常') {
                            val.result.records[i].buttonData = [ {key: 'logOut', value: '注销', if: false, buttonCode: appConfig.funcObject.group.GrouppostlogOut}, {key: 'app', value: '应用权限', if: false, buttonCode: appConfig.funcObject.group.grouppostApp}];
                        } else {
                            val.result.records[i].buttonData = [ {key: 'start', value: '启用', if: false, buttonCode: appConfig.funcObject.group.EnableGrouppost}, {key: 'dels', value: '删除', if: false, buttonCode: appConfig.funcObject.group.GrouppostDel}];
                        }
                        if (val.result.records[i].startDate) {
                            val.result.records[i].startDate = moment(val.result.records[i].startDate).format('YYYY-MM-DD');
                        }

                        if (val.result.records[i].endDate) {
                            val.result.records[i].endDate = moment(val.result.records[i].endDate).format('YYYY-MM-DD');
                        }
                    }
                    this.postdata = val.result.records;
                    console.log(this.postdata)
                    this.posttotal = val.result.total;
                });

    }



    queryGroup(groupCode) {
        this.utilityService.getData(appConfig.serverUrl  + appConfig.API.omGroups + '/' + groupCode )
            .subscribe(
                (val) => {
                    this.orgGuid = val.result.guidOrg;
                    this.groupGuid = val.result.guid;
                },
            );
    }


    // 枚举值转换
    // 岗位类型转换
    postType(event) {
        if (event.positionType === '机构岗位') {
            event.positionType = '01';
        } else if (event.positionType === '工作组岗位') {
            event.positionType = '02';
        }
    }
    // 岗位状态转换
    Statuspost(event) {
        if (event.positionStatus === '正常') {
            event.positionStatus = 'running';
        } else if (event.positionStatus === '注销') {
            event.positionStatus = 'cancel';
        }
    }


    /* 获取工作组下可分配岗位*/
    queryOrgPost(postGuid?) {
        if(postGuid) {
            let objJson = {
                positionId: postGuid,
                groupId: this.groupGuid
            }
            this.utilityService.postData(appConfig.serverUrl + appConfig.API.listsByGroupId, objJson)
                .subscribe(
                    (val) => {
                        this.Parentsguid = val.result;
                    });
        } else {
            let objJson = {
                groupId: this.groupGuid
            }
            this.utilityService.postData(appConfig.serverUrl + appConfig.API.listsByGroupId, objJson)
                .subscribe(
                    (val) => {
                        this.Parentsguid = val.result;
                    });
        }
    }

    // 想一下，能否把这三个方法封装到一个ts里面，引入即可，不然每次都写着三个方法不太现实。
    // 列表组件传过来的内容
    addPostHandler(event) {
        this.ifshow = false; // 默认是基础信息
        this.isappcodeSlash = false;
        this.postAdd = new PostModule(); // 重新清空赋值
        if (event === 'add') {
            this.postAddEdit = '新增岗位'
            this.queryOrgPost();
            this.postAdd.positionStatus = 'running';
            this.startDate = false; // 默认false
            this.parentPost = false; // 默认false
            this.endDate = false; // 默认false
            this.GroupmodalVisible = true;  // 此时点击了列表组件的新增，打开模态框
            this.postAdd.positionType = '02';
            this.isEdit = false;
        } else { // 代表修改，把修改的内容传递进去，重新渲染
            if (event.guidParents !== '') {
                this.parentPost = true;
            }
            if (event.startDate) {
                this.startDate = true;
            }
            if(event.endDate) {
                this.endDate = true;
            }
            this.postAddEdit = '修改岗位'
            this.postAdd.positionType = '02';
            this.GroupmodalVisible = true;  // 此时点击了列表组件的新增，打开模态框
            this.Parentsguid = [];
            this.Statuspost(event)
            this.queryOrgPost(event.guid);
            this.postType(event)
            this.postAdd = event;

            this.isEdit = true;
        }
    }


    // 验证是否重复
    AppCodeexit(postAddEdit, postCode) {
        if(postAddEdit === '新增岗位') {
            let objJson = {
                guid: '',
                positionCode: postCode,
                guidMapping: this.groupGuid
            }
            this.utilityService.postData(appConfig.serverUrl  + appConfig.API.existAddPositionCode , objJson)
                .subscribe(
                    (sus) => {
                        if (sus.result) {
                            this.isappcodeSlash = true; // 重复
                        } else {
                            this.isappcodeSlash = false; // 不重复
                        }
                    },
                    (error) => {
                        this.nznot.create('error', error.msg , error.msg);
                    }
                );
        } else {
            let objJson = {
                guid: this.postAdd.guid,
                positionCode: postCode,
                guidMapping: this.groupGuid
            }
            this.utilityService.postData(appConfig.serverUrl  + appConfig.API.existUpdatePositionCode , objJson)
                .subscribe(
                    (sus) => {
                        if (sus.result) {
                            this.isappcodeSlash = true; // 重复
                        } else {
                            this.isappcodeSlash = false; // 不重复
                        }
                    },
                    (error) => {
                        this.nznot.create('error', error.msg , error.msg);
                    }
                );
        }
    }



    buttonPostEvent(event) {
        if (event.names) {
            if (event.names.key === 'logOut') {
                this.utilityService.putData(appConfig.serverUrl  + appConfig.API.cancel + '/' + event.guid )
                    .subscribe(
                        (val) => {
                            console.log(val)
                            this.nznot.create('success', val.msg , val.msg);
                            this.getPostData();
                        },
                        (error) => {
                            this.nznot.create('error', error.msg , error.msg);
                        }
                    );
            }

            if (event.names.key === 'app') {
                this.showAdd = true; // 没有新增
                this.postName = event.postName;
                this.postGuid = event.guid;
                this.appConfit = '';
                this.modelSelect = false; // 打开弹出框
                this.postTitle = '岗位' + event.positionName + '可以使用的应用系统'
                this.empdistribution = true; // 弹出在岗员工数代码
                this.getPostApp(); // 查询所有的应用
                this.getPostApplist(); // 查询已分配的权限

            }

            if (event.names.key === 'dels') {
                this.deleatData(event);
            }

            if (event.names.key === 'start') {
                this.utilityService.putData(appConfig.serverUrl  + appConfig.API.running + '/' + event.guid )
                    .subscribe(
                        (val) => {
                            this.nznot.create('success', val.msg , val.msg);
                            this.getPostData();
                        },
                        (error) => {
                            this.nznot.create('error', error.msg , error.msg);
                        }
                    );
            }
        } else {

        }
    }


    // 列表传入的翻页数据
    monitorPostHandler(event) {
        this.pageIndex = event;
        this.getPostData();
    }

    // 接受子组件删除的数据 单条还是多条
    deleatData(event) {
        this.modal.open({
            title: '是否删除',
            content: '您是否确认删除所选岗位?',
            okText: '确定',
            cancelText: '取消',
            onOk: () => {
                this.utilityService.deleatData(appConfig.serverUrl + appConfig.API.postDel + '/' + event.guid)
                    .subscribe(
                        (val) => {
                            this.nznot.create('success', val.msg , val.msg);
                            if ( !(( this.posttotal - 1) % 10)) {
                                // if ( !(( this.total - this.acfundata.length) % 10)) { // 支持批量删除的方法
                                this.post.pi -- ;
                                this.getPostData();
                            }
                            this.getPostData();
                        },
                        (error) => {
                            this.nznot.create('error', error.msg , error.msg);
                        });
            },
            onCancel: () => {
            }
        });
    }

    // 批量删除
    deletePostBatch(event) {
        this.modal.open({
            title: '是否删除',
            content: '您是否确认删除这' + event.length + '条岗位吗?',
            okText: '确定',
            cancelText: '取消',
            onOk: () => {
                let delarray = [];
                for( let i = 0; i < event.length; i++) {
                    delarray.push(event[i].guid);
                }
                let deletaObj = {
                    deleteList: delarray,
                    guid: this.groupGuid
                }
                this.utilityService.postData(appConfig.serverUrl + appConfig.API.postDelte, deletaObj )
                    .subscribe(
                        (val) => {
                            this.getPostData();
                            this.selectedPostRows = []
                            this.nznot.create('success', val.msg , val.msg);
                        },
                        (error) => {
                            this.nznot.create('error', error.msg , error.msg);
                        });
            },
            onCancel: () => {
                this.getPostData();
                this.selectedPostRows = []
            }
        });
    }


    // 列表按钮方法
    buttonPostDataHandler(event) {
        console.log(event); // 根据event.value来判断不同的请求，来获取结果和方法或者进行路由的跳转
        if (event.value ===  'Authority') {
            console.log(event.key);
        }

        if (event.value ===  'Overview') {
            console.log(event.key);
        }

    }



    postInfo: any;
    // 处理行为代码，跳转、弹出框、其他交互
    isActPostive(event) {
        this.postInfo = event; // 保存岗位信息
        this.empdistribution = true; // 弹出在岗员工数代码
        this.modelSelect = true;
        this.postTitle = '岗位' + event.parentName + '下的员工'
        this.postGuid = event.guid;
        this.getEmpData(event.guid);
        this.getEmpList(event.guid);
    }


    objJSon = {};
    // 搜索框
    postsearch() {
        this.objJSon = this.post;
        this.getPostData(this.post);
    }

    postreset() {
        this.objJSon = {};
        this.post = new PostModule();
        this.getPostData();
    }
    // switch开关
    switchchange(item, status) {
        if (item === 'parentPost') {
            this.parentPost = status;
        }
        if (item === 'startDate') {
            this.startDate = status;
        }
        if (item === 'endDate') {
            this.endDate = status;
        }
    }


    canel() {
        this.GroupmodalVisible = false;
        this.getPostData();
    }

    // 弹出框保存组件
    postsave() {
        const jsonOption = this.postAdd;
        jsonOption.guidMapping = this.groupGuid;
        jsonOption.groupCode = this.groupCode;
        jsonOption.isLeaf = 'Y' ;
        jsonOption.subCount = 0 ;
        jsonOption.positionType = '02'; // 默认是工作组岗位
        if (!this.isEdit) { // 新增数据
            if (this.startDate && jsonOption.startDate === undefined) { // 如果是true 那么就默认当天
                jsonOption.startDate =  moment(new Date()).format('YYYY-MM-DD'); // 默认当前时间
            }
            if (this.endDate && jsonOption.endDate === undefined) { // 如果是true 那么就默认当天
                jsonOption.endDate =  moment(new Date()).format('YYYY-MM-DD'); // 默认当前时间
            }
            const jsonAjax = {
                groupCode: this.groupCode,
                omPositionRequest: jsonOption
            }
            this.utilityService.postData(appConfig.serverUrl  + appConfig.API.groupPosition, jsonAjax)
                .subscribe(
                    (val) => {
                        this.nznot.create('success', val.msg , val.msg);
                        this.getPostData();
                    },
                    (error) => {
                        this.nznot.create('error', error.msg , error.msg);
                    }
                );
        } else {
            this.utilityService.putData(appConfig.serverUrl  + appConfig.API.postDel, jsonOption)
                .subscribe(
                    (val) => {
                        this.getPostData();
                        this.nznot.create('success', val.msg , val.msg);
                    },
                    (error) => {
                        this.nznot.create('error', error.msg , error.msg);
                    }
                );
        }
        this.GroupmodalVisible = false;
    }


    // 在岗员工数代码部分
    empDataheader = [  // 配置表头内容
        {value: '员工姓名' , key: 'empName', isclick: false},
        {value: '操作员', key: 'operatorName',  isclick:  false},
        {value: '员工状态' , key: 'empstatus', isclick: false},
        {value: '电话号码' , key: 'mobileno', isclick: false},
        {value: '入职日期' , key: 'indate', isclick: false},
    ];


    EmpData = {
        morebutton: true,
        buttons: [
            {key: 'Onboarding' , value: '入职'},
            {key: 'Departure' , value: '离职'},
            {key: 'Overview' , value: '查看概况'},
            {key: 'operator' , value: '操作员修改'},
        ]
    };

    empTotal: number; // 总页数
    empData: any; // 总数据
    showAdd: boolean; // 是否显示新增按钮


    getEmpList(guid) {
        this.page = {
            condition: {
                guidOrg: this.groupCode,
                guidPosition: guid,
            },
            page: {
                current: this.emp.pi,
                size: this.emp.size,
            }
        };
        this.utilityService.postData(appConfig.serverUrl + appConfig.API.queryByOrgPosition,  this.page)
            .subscribe(
                (val) => {
                    console.log(val.result)
                    // 没有在岗员工，模拟一下
                    for (let i = 0; i < val.result.records.length; i++) {
                        val.result.records[i].indate =  moment(val.result.records[i].indate).format('YYYY-MM-DD');
                        val.result.records[i].buttonData = [{key: 'dels', value: '删除', if: false, buttonCode: appConfig.funcObject.group.delGroupEmp}];
                    }
                    this.empData = val.result.records;
                    this.empTotal = val.result.total;
                },
                (error) => {
                    this.nznot.create('error', error.msg , error.msg);
                });
    }
    // 新增方法
    addEmp(e) {
        console.log(e);
    }
    // 顶部按钮事件
    buttonEmp(e) {
        console.log(e);
    }

    empsave() {
        this.empdistribution = false; // 弹出在岗员工数代码
        this.getPostData();
    }

    empEvent(e) {
        if (e.names) {
            if (e.names.key === 'dels') {
                this.utilityService.deleatData(appConfig.serverUrl + appConfig.API.postDelemp + '/' + e.guid + '/' + this.postInfo.guid )
                    .subscribe(
                        (val) => {
                            this.nznot.create('success', val.msg , val.msg);
                            this.getEmpList(this.postGuid); // 重新查询列表内容
                        },
                        (error) => {
                            this.nznot.create('error', error.msg , error.msg);
                        });
            }
        }
    }

    // 翻页事件
    empHandler(e) {

    }
    // 删除事件
    deleatEmp(e) {

    }

    // 选中事件
    selectedemp() {

    }




    // 给岗位添加员工

    pages: PageModule = new PageModule;
    addEmpClick() {
        if (this.selectedOption) {
            const josnObj = {
                guidEmp: this.selectedOption,
                guidPosition: this.postGuid,
                ismain: 'N'
            }
            this.utilityService.postData(appConfig.serverUrl + appConfig.API.empAdd,  josnObj)
                .subscribe(
                    (val) => {
                        this.nznot.create('success', val.msg , val.msg);
                        this.getPostData();
                        this.getEmpList(this.postGuid); // 重新查询列表内容
                        this.getEmpData(this.postGuid); // 重新查询员工内容
                    },
                    (error) => {
                        this.nznot.create('error', error.msg , error.msg);
                    });
        } else {
            this.nznot.create('error', '请最起码选择一个员工进行添加' , '请最起码选择一个员工进行添加');
        }


    }

    // 岗位应用权限内容
    searchOptionse; // 选择显示的内容
    selectedMultipleOption; // 多选的内容
    array = []; // 定义数组 用来清空
    Apptotal: number; // 应用翻页
    postName: string; // 岗位名称
    appData: any[] = []; // 表格数据
    AppheaderData = [  // 配置表头内容
        { value: '应用名称', key: 'appName', isclick: false },
        { value: '应用类型', key: 'appType', isclick: false },
        { value: '应用开通时间', key: 'openDate', isclick: false },

    ];

    // 查询所有应用（已经分配之外的除外）
    getPostApp() {
        this.utilityService.getData(appConfig.serverUrl + appConfig.API.appNoth + '/' + this.postGuid)
            .subscribe(
                (val) => {

                    this.searchOptions = val.result;

                }
            );
    }

    // 查询岗位下已经有的应用列表
    getPostApplist() {
        this.page = {
            page: {
                current: this.pages.pi,
                size: this.pages.size,
            }
        };
        // 模拟一下
        this.utilityService.postData(appConfig.serverUrl + appConfig.API.listByPosition + '/' + this.postGuid,  this.page)
            .subscribe(
                (val) => {
                    console.log(val)
                    for (let i = 0; i < val.result.records.length; i++ ) {
                        val.result.records[i].buttonData = [{key: 'dels', value: '删除', buttonCode: appConfig.funcObject.group.groupDelApppost}];
                        val.result.records[i].openDate =  moment(new Date()).format('YYYY-MM-DD'); // 默认当前时间
                    }
                    this.appData = val.result.records;
                    this.Apptotal = val.result.total;
                }
            );
    }




    // 给岗位新增应用
    postappAdd(event) {
        console.log(event)
        if(event.appList && event.appList.length > 0) {
            this.utilityService.postData(appConfig.serverUrl + appConfig.API.addByList,  event)
                .subscribe(
                    (val) => {
                        this.nznot.create('success', val.msg , val.msg);
                        this.selectedMultipleOption = [];
                        // 重新查询岗位信息
                        this.getPostApplist();
                        this.getPostApp(); // 重新查询
                    },
                    (error) => {
                        this.nznot.create('error', error.msg , error.msg);
                    });
        } else {
            this.nznot.create('error', '请必须选择一个应用',  '请必须选择一个应用');
        }

    }


    appClick() {
        console.log(this.selectedMultipleOption); // 传入后台，渲染
        const jsonObj = {
            guidList : this.selectedMultipleOption,
        };
        const addApp = {
            guidPosition: this.postGuid,
            appList  : this.selectedMultipleOption,
        }
        console.log(addApp);
        // 调用新增接口方法
        this.postappAdd(addApp)

        // 查询所有应用
        this.getPostApp();
        this.getPostApplist();
    }


    // 应用列表方法
    // 列表组件传过来的内容
    addappHandler(event) {

    }


    // 列表传入的翻页数据
    monitorappHandler(event) {
        console.log(event)
        this.pages.pi = event;
        this.page = {
            page: {
                current: event, // 页码
                size: this.pages.size, //  每页个数
            }
        };
        this.getPostApplist();
    }


    // 列表按钮方法
    buttonappDataHandler(event) {
        console.log(event); // 根据event.value来判断不同的请求，来获取结果和方法或者进行路由的跳转
    }

    selectedappRow(event) { // 选中方法，折叠层按钮显示方法
    }


    // 删除按钮
    appDel(event) {
        // 传第三表的id  event.id 即可
        this.utilityService.deleatData(appConfig.serverUrl + appConfig.API.appDelpost + '/' + event.guid + '/' + this.postGuid )
            .subscribe(
                (val) => {
                    this.nznot.create('success', val.msg , val.msg);
                    this.getPostApp();
                    this.getPostApplist();
                },
                (error) => {
                    this.nznot.create('error', error.msg , error.msg);
                });

    }


    // 批量删除岗位下应用
    deleteBatchApp(event) {
        this.empdistribution = false;
        this.modal.open({
            title: '是否删除',
            content: '您是否确认删除这' + event.length + '条应用吗?',
            okText: '确定',
            cancelText: '取消',
            onOk: () => {
                let delarray = [];
                for( let i = 0; i < event.length; i++) {
                    delarray.push(event[i].guid);
                }
                let deletaObj = {
                    deleteList: delarray,
                    guid: this.postGuid
                }
                this.utilityService.postData(appConfig.serverUrl + appConfig.API.batchAppDelete, deletaObj )
                    .subscribe(
                        (val) => {
                            this.selectedPostRows = [];
                            this.empdistribution = true;
                            this.nznot.create('success', val.msg , val.msg);
                            this.getPostApp()
                            this.getPostApplist();
                        },
                        (error) => {
                            this.selectedPostRows = []
                            this.nznot.create('error', error.msg , error.msg);
                        });
            },
            onCancel: () => {
                this.selectedPostRows = []
                this.getPostData()
            }
        });
    }


    appsave() {
        this.empdistribution = false;
    }








    /*-----------------------------------应用权限-----------------------------------*/
    searchOptionsAuth; // 选择显示的内容
    selectedMultipleOptionAuth; // 多选的内容
    configTitle: any;
    total: number;

    data: any[] = []; // 表格数据
    headerData = [  // 配置表头内容
        { value: '应用名称', key: 'appName', isclick: false },
        { value: '应用类型', key: 'appType', isclick: false },
        { value: '应用开通时间', key: 'openDate', isclick: false },

    ];
    moreData = {
        morebutton: true,
        buttons: [
            { key: 'Overview', value: '查看概况' }
        ]
    };

    selectedRows: any;

    getInitAuthority() {
        this.groupGuid = this.id; // 拿到父组件传过来的组织机构的guid来进行操作
        this.showAdd = true;
        this.configTitle = {value: '删除', buttonCode: appConfig.funcObject.group.queryGroup};// 没有删除删除工作组下行为代码，先用查询的
        this.querygroupApp();
    }



    // 查询不在工作组内的其他应用
    nzOpenChange() {
        this.utilityService.getData(appConfig.serverUrl  + appConfig.API.omGroups + '/' + this.groupGuid + '/availableApp')
            .subscribe(
                (val) => {
                    this.searchOptionsAuth = val.result;
                });
    }


    // 查询工作组下的应用
    querygroupApp() {
        this.page = {
            page: {
                current: this.pages.pi,
                size: this.pages.size,
            }
        };

        this.utilityService.postData(appConfig.serverUrl  + appConfig.API.omGroups + '/' + this.groupGuid + '/app', this.page)
            .subscribe(
                (val) => {
                    console.log(val.result.records)
                    for (let i = 0; i < val.result.records.length; i ++ ) {
                        if(val.result.records[i].openDate) {
                            val.result.records[i].openDate =  moment(val.result.records[i].openDate).format('YYYY-MM-DD');
                        }
                    }
                    this.data = val.result.records;
                    this.total = val.result.total;
                });


    }




    appAuthClick() {
        console.log(this.selectedMultipleOptionAuth); // 传入后台，渲染
        const jsonObj = {
            groupCode: this.groupGuid,
            appGuidList: this.selectedMultipleOptionAuth,
        }

        this.utilityService.postData(appConfig.serverUrl  + appConfig.API.groupApp, jsonObj)
            .subscribe(
                (val) => {
                    this.nznot.create('success', val.msg , val.msg);
                    this.selectedMultipleOptionAuth = [];
                    this.querygroupApp();
                });
    }






    // 列表组件传过来的内容
    addHandler(event) {
        // 删除应用
        this.utilityService.deleatData(appConfig.serverUrl  + appConfig.API.omGroups + '/' + this.groupGuid + '/app/' + event.guid )
            .subscribe(
                (val) => {
                    this.nznot.create('success', val.msg , val.msg);
                    this.querygroupApp();
                },
                (error) => {
                    this.nznot.create('error', error.msg , error.msg);
                });

    }

    deleteBatch(event) {
        this.modal.open({
            title: '是否删除',
            content: '您是否确认删除这' + event.length + '条应用吗?',
            okText: '确定',
            cancelText: '取消',
            onOk: () => {
                let delarray = [];
                for( let i = 0; i < event.length; i++) {
                    delarray.push(event[i].guid);
                }
                let deletaObj = {
                    guid: this.id,
                    deleteList: delarray
                }
                this.utilityService.postData(appConfig.serverUrl + appConfig.API.groupBath, deletaObj )
                    .subscribe(
                        (val) => {
                            this.selectedRows = [];
                            this.querygroupApp();
                            this.nznot.create('success', val.msg , val.msg);
                        },
                        (error) => {
                            this.nznot.create('error', error.msg , error.msg);
                        });
            },
            onCancel: () => {
                this.selectedRows = [];
                this.querygroupApp();
            }
        });
    }


    // 列表传入的翻页数据
    monitorHandler(event) {
        console.log(event)
        this.pages.pi = event;
        this.page = {
            page: {
                current: event, // 页码
                size: this.pages.size, //  每页个数
            }
        };
        this.querygroupApp();
    }


    // 列表按钮方法
    buttonDataHandler(event) {
        console.log(event); // 根据event.value来判断不同的请求，来获取结果和方法或者进行路由的跳转
    }

    selectedRow(event) { // 选中方法，折叠层按钮显示方法
    }

    // 处理行为代码，跳转、弹出框、其他交互
    isActive(event) {
        console.log(event); // 拿到数据进行判断，是跳转路由还是弹出框弹出

    }
}

